<!-- 外发结算作业-4：蹇泽阳 -->
<template>
  <div class="app-container">
    <Find :OriginalFilter="{ static: true }" :formList="formList" @findClicked="findClicked" />
    <Find :searchImg="false" :OriginalFilter="{ static: true }" :formList="formList2" @findClicked="findClicked2" />
    <div class="flex mt10" style="width: 100%; background-color: white">
      <el-card shadow="never" :body-style="{ padding: '5px 10px 5px' }">
        <h1 class="f16">外发资料</h1>
        <Table
          :tableHeader="tableHeader"
          :tableData="tableData"
          selection
          class="mt10"
          :isLoading="isLoading"
          @selectList="selectTableList"
          @currentRow="currentRow"
        />
        <PageModule
          :PageData="{ total, pageSizeShow: true, buttonS: true }"
          :layout="'prev, pager'"
          @pageSizeChange="handleSizeChange"
          @pageChange="handleCurrentChange"
        />
      </el-card>
      <el-card shadow="never" :body-style="{ padding: '5px 10px 5px' }">
        <h1 class="f16">外发明细</h1>
        <Table
          :tableHeader="tableHeader2"
          :tableData="tableData2"
          selection
          @selectList="selectTableList2"
          class="mt10"
          :isLoading="isLoading2"
          @currentRow="currentRow2"
          :summaryData="summaryData2"
          summary
        />
        <PageModule
          :PageData="{ total: total2, pageSizeShow: true, buttonS: true }"
          :layout="'prev, pager'"
          @pageSizeChange="handleSizeChange2"
          @pageChange="handleCurrentChange2"
        />
      </el-card>
      <el-card shadow="never" :body-style="{ padding: '5px 10px 5px' }" class="mt10">
        <h1 class="f16">外发号码明细</h1>
        <Table :tableHeader="tableHeader3" :tableData="tableData3" :isLoading="isLoading3" />
      </el-card>
    </div>

    <el-drawer v-model="drawer" :direction="'ttb'" size="small" :with-header="false">
      <span @click="drawer = false" style="float: right; cursor: pointer; color: rgb(7, 7, 7)">X</span>
      <Find :searchImg="false" :formList="formList10" @findClicked="findClicked10" />
      <Find :searchImg="false" :formList="formList11" @findClicked="findClicked11" />
      <div class="flex mt10 JCC" style="width: 100%; background-color: white">
        <el-card shadow="never" :body-style="{ padding: '5px 10px 5px' }">
          <h1 class="f16">选择外发指令</h1>
          <Table
            :tableHeader="tableHeader10"
            :tableData="tableData10"
            class="mt10"
            :outTableHeight="150"
            :isLoading="isLoading10"
            @currentRow="currentRow10"
            :summaryData="summaryData10"
            summary
          />
        </el-card>
        <el-card shadow="never" :body-style="{ padding: '5px 10px 5px' }">
          <h1 class="f16">号码明细</h1>
          <Table :tableHeader="tableHeader11" :tableData="tableData11" class="mt10" :outTableHeight="350" />
        </el-card>
      </div>
      <PageModule :PageData="{ total: total10, buttonS: true }" @pageSizeChange="handleSizeChange10" @pageChange="handleCurrentChange10" />
    </el-drawer>
  </div>
</template>
<script lang="ts">
import { defineComponent } from 'vue'
import LoginWork from '@/utils/LoginWork'
import fileRequest from '@/utils/fileRequest'
import JMessage from '@/utils/JMessage'
export default defineComponent({
  name: 'OutgoingSettlementOperations'
})
</script>
<script lang="ts" setup>
import { i18n, Jzhcn } from '@/i18n'
import type { formListType } from '@/components/Find/index.vue'
import { ref } from 'vue'
import { ElMessage, ElMessageBox } from 'element-plus'
import service from '@/utils/request'
import { debounce } from 'lodash'
import { onMounted, watch } from 'vue'

const formList = ref([
  {
    type: 'input',
    inputPlaceholder: '外发单号',
    inputValue: ''
  },
  {
    type: 'date',
    dateLabel: '外发日期',
    dateValue: ''
  },
  {
    type: 'selectJ',
    selectValue: '',
    selectP: '厂商',
    selectLabel: '',
    selectOptions: []
  },
  {
    dateType: 'month',
    type: 'dateMonth',
    dateLabel: '对账月份',
    dateValue: ''
  },
  {
    type: 'input',
    inputPlaceholder: '指令',
    inputValue: ''
  },
  {
    type: 'checkbox',
    checkboxLabel: '未检核',
    checked: true
  },
  {
    type: 'checkbox',
    checkboxLabel: '已检核',
    checked: true
  },
  {
    type: 'button',
    checkboxLabel: '置空',
    bgColor: '#1890FF'
  }
]) as any

const formList2 = ref([
  {
    dateType: 'month',
    type: 'dateMonth',
    dateLabel: '对账月份',
    dateValue: ''
  },
  {
    type: 'select',
    selectValue: '',
    selectP: '结算方式',
    selectLabel: '',
    selectOptions: []
  },
  {
    type: 'button',
    checkboxLabel: '打勾记录检核'
  },
  {
    type: 'button',
    checkboxLabel: '打勾记录取消检核'
  },
  {
    type: 'button',
    checkboxLabel: '明细查询'
  }
]) as any

// 表一模块
// 表一按钮
const findClicked = (content: string) => {
  if (content === '置空') {
    formList.value.forEach((item: any) => {
      item.inputValue = ''
      item.selectValue = ''
      item.dateValue = ''
    })
  }
}
const tableData = ref([])
const isLoading = ref(true)
// 分页器
const currentPage = ref(1)
const pageSize = ref(40)
const total = ref(0)
const handleSizeChange = (val: number) => {
  pageSize.value = val
  getTableList()
}
const handleCurrentChange = (val: number) => {
  currentPage.value = val
  getTableList()
}
// 表格计算函数
const cfmFlag = () => {
  const Unaudited = formList.value.find((item: any) => item.type === 'checkbox' && i18n.global.t(item.checkboxLabel) === '未检核')
  const Audited = formList.value.find((item: any) => item.type === 'checkbox' && i18n.global.t(item.checkboxLabel) === '已检核')
  if (!Unaudited || !Audited) return
  if (Unaudited.checked && Audited.checked) {
    return ''
  } else if (Unaudited.checked) {
    return 0
  } else if (Audited.checked) {
    return 1
  } else {
    ElMessage('必须至少选择一项')
    Unaudited.checked = true
    Audited.checked = true
    return ''
  }
}
// 获取表数据
const getTableList = debounce(async () => {
  isLoading.value = true
  let tableDataList = await service.post<any, any>('/mtlCosts/outListTempQuery', {
    cfmType: cfmFlag(), //0.未检核 1.已检核
    financeYymm: formList.value.find(
      (item: any) => item.dateLabel && Jzhcn.Find[item.dateLabel.split('.')[1] as keyof typeof Jzhcn.Find] === '对账月份'
    )?.dateValue,
    lotNo: formList.value.find(
      (item: any) => item.inputPlaceholder && Jzhcn.Find[item.inputPlaceholder.split('.')[1] as keyof typeof Jzhcn.Find] === '指令'
    )?.inputValue,
    purDateEnd: formList.value.find(
      (item: any) => item.dateLabel && Jzhcn.Find[item.dateLabel.split('.')[1] as keyof typeof Jzhcn.Find] === '外发日期'
    )?.dateValue?.[1],
    purDateStart: formList.value.find(
      (item: any) => item.dateLabel && Jzhcn.Find[item.dateLabel.split('.')[1] as keyof typeof Jzhcn.Find] === '外发日期'
    )?.dateValue?.[0],
    slipNo: formList.value.find(
      (item: any) => item.inputPlaceholder && Jzhcn.Find[item.inputPlaceholder.split('.')[1] as keyof typeof Jzhcn.Find] === '外发单号'
    )?.inputValue,
    vendor: formList.value.find((item: any) => item.selectP && Jzhcn.Find[item.selectP.split('.')[1] as keyof typeof Jzhcn.Find] === '厂商')
      ?.selectValue,
    pageNum: currentPage.value,
    pageSize: pageSize.value
  })
  isLoading.value = false
  tableData.value = tableDataList.dtos.map((item: any) => {
    if (item.cfmFlag === 'Y') item.backgroundColor = '#80FF00'
    return item
  })
  total.value = tableDataList.total
  currentRow()
}, 500)
onMounted(() => {
  getTableList()
})
watch(
  () =>
    formList.value.map((item: any) => {
      item.selectValue, item.inputValue, item.dateValue, item.checked
    }),
  () => {
    getTableList()
  }
)
const tableHeader = ref([
  {
    backgroundColor: true,
    width: 120,
    label: '外发单号',
    prop: 'slipNo'
  },
  {
    width: 100,
    label: '外发日期',
    prop: 'purDate'
  },
  {
    width: 75,
    label: '对账月份',
    prop: 'financeYymm'
  }
])
// 点击表给另一张表传数据
const currentTableRow = ref({}) as any
const currentRow = async (row: any = tableData.value[0] ? tableData.value[0] : {}) => {
  currentTableRow.value = row
  getTableList2()
  getTableList3()
}
const selectedLists = ref([])
const selectTableList = (selectedList: any) => {
  selectedLists.value = selectedList
  if (selectedLists.value.length !== 0) {
    tableData2.value.forEach((item: any) => (item.change = null))
  } else {
    tableData2.value.forEach((item: any) => (item.change = false))
  }
}
const selectedLists2 = ref([])
const selectTableList2 = (selectedList: any) => {
  selectedLists2.value = selectedList
  if (selectedLists2.value.length !== 0) {
    tableData.value.forEach((item: any) => (item.change = null))
  } else {
    tableData.value.forEach((item: any) => (item.change = false))
  }
}

// 表二模块
// 表二按钮
const findClicked2 = async (content: string) => {
  if (content === '置空') {
    formList2.value.forEach((item: any) => {
      item.inputValue = ''
      item.selectValue = ''
      item.dateValue = ''
    })
  }
  if (content === '明细查询') {
    drawer.value = true
    getTableList10()
    getSelectList2()
  }
  if (content === '打勾记录检核') {
    const month = formList2.value.find(
      (item: any) => item.dateLabel && Jzhcn.Find[item.dateLabel.split('.')[1] as keyof typeof Jzhcn.Find] === '对账月份'
    )?.dateValue
    const type = formList2.value[1].selectValue
    if (!month || !type) {
      JMessage.warning('请输入对账月份和结算方式')
      return
    }
    if (selectedLists.value.length === 0 && selectedLists2.value.length === 0) {
      JMessage.warning('请勾选表格数据')
      return
    }
    if (selectedLists.value.some((item: any) => item.cfmFlag === 'Y')) {
      JMessage.warning('已检核数据不能重复检核')
      return
    }

    const selectList = selectedLists.value.length === 0 ? selectedLists2.value : selectedLists.value
    const res = (await LoginWork.put(`/mtlCosts/outListTempCfm?type=${1}&financeYymm=${month}&accountName=${type}&retryFlag=${0}`, selectList)) as any
    if (res.code === 200) {
      JMessage.success('检核成功')
      formList2.value.find(
        (item: any) => item.dateLabel && Jzhcn.Find[item.dateLabel.split('.')[1] as keyof typeof Jzhcn.Find] === '对账月份'
      ).dateValue = ''
      formList2.value[1].selectValue = ''
      getTableList()
    } else if (res.code === 202) {
      JMessage.warning(res.message)
      ElMessageBox.confirm(res.message, {
        confirmButtonText: '确认',
        cancelButtonText: '取消',
        type: 'warning'
      })
        .then(async () => {
          const res = (await LoginWork.put(
            `/mtlCosts/outListTempCfm?type=${1}&financeYymm=${month}&accountName=${type}&retryFlag=${1}`,
            selectList
          )) as any
          if (res.code === 200) {
            JMessage.success('检核成功')
            getTableList()
          } else {
            JMessage.error(res.message)
          }
        })
        .catch(() => {
          ElMessage({
            type: 'info',
            message: '取消检核'
          })
        })
    } else {
      JMessage.error(res.message)
    }
  }
  if (content === '打勾记录取消检核') {
    if (selectedLists.value.length === 0 && selectedLists2.value.length === 0) {
      JMessage.warning('请勾选表格数据')
      return
    }
    const selectList = selectedLists.value.length === 0 ? selectedLists2.value : selectedLists.value

    const res = (await LoginWork.put(`/mtlCosts/outListTempCfm?type=${0}&retryFlag=${0}`, selectList)) as any
    if (res.code === 200) {
      JMessage.success('取消检核成功')
      formList2.value.find(
        (item: any) => item.dateLabel && Jzhcn.Find[item.dateLabel.split('.')[1] as keyof typeof Jzhcn.Find] === '对账月份'
      ).dateValue = ''
      formList2.value[1].selectValue = ''
      getTableList()
    } else {
      JMessage.error(res.message)
    }
  }
}
const tableData2 = ref([])
const isLoading2 = ref(true)
// 总计
interface summaryDataType {
  index: number
  num: number | undefined
}
const summaryData2 = ref<summaryDataType[]>([
  {
    index: 6,
    num: 0
  },
  {
    index: 10,
    num: 0
  }
])
// 分页器
const currentPage2 = ref(1)
const pageSize2 = ref(40)
const total2 = ref(0)
const handleSizeChange2 = (val: number) => {
  pageSize2.value = val
  getTableList2()
}
const handleCurrentChange2 = (val: number) => {
  currentPage2.value = val
  getTableList2()
}
// 获取表数据
const getTableList2 = debounce(async () => {
  isLoading2.value = true
  let tableDataList = await service.post<any, any>('/mtlCosts/outListDetailQuery', {
    ...currentTableRow.value,
    pageNum: currentPage2.value,
    pageSize: pageSize2.value
  })
  isLoading2.value = false
  tableData2.value = tableDataList.dtos.map((item: any) => {
    if (item.financeYymm) {
      item.backgroundColor = '#80FF00'
    }
    return item
  })
  total2.value = tableDataList.total
  currentRow2()
  summaryData2.value[0].num = tableDataList.sum.orderQtySum
  summaryData2.value[1].num = tableDataList.sum.amtSum
}, 500)
const tableHeader2 = ref([
  {
    backgroundColor: true,
    label: '厂商名称',
    prop: 'vendor'
  },
  {
    backgroundColor: true,
    label: '指令',
    prop: 'lotNo'
  },
  {
    backgroundColor: true,
    label: '型体',
    prop: 'style'
  },
  {
    backgroundColor: true,
    label: '工艺',
    prop: 'process'
  },
  {
    backgroundColor: true,
    label: '部位名称',
    prop: 'partName'
  },
  {
    backgroundColor: true,
    label: '片数',
    prop: 'cutNum',
    width: '55px'
  },
  {
    backgroundColor: true,
    label: '订单量',
    prop: 'ordQty',
    width: '55px'
  },
  {
    backgroundColor: true,
    label: '外发数量',
    prop: 'purQty',
    width: '55px'
  },
  // {
  //   label: '入库量',
  //   prop: 'recQty',
  //   width: '55px'
  // },
  {
    backgroundColor: true,
    label: '单价',
    prop: 'price',
    width: '55px'
  },
  {
    backgroundColor: true,
    label: '金额',
    prop: 'amt',
    width: '55px'
  },
  {
    backgroundColor: true,
    label: '交期',
    prop: 'deliveryDate'
  },
  {
    backgroundColor: true,
    label: '备注',
    prop: 'purMemo'
  },
  {
    backgroundColor: true,
    label: '结算方式',
    prop: 'accountName'
  },
  {
    backgroundColor: true,
    label: '结算月份',
    prop: 'financeYymm'
  },
  {
    backgroundColor: true,
    width: 120,
    label: '结算单号',
    prop: 'balanceNo'
  }
])
// 点击表给另一张表传数据
const currentTableRow2 = ref({}) as any
const currentRow2 = async (row: any = tableData2.value[0]) => {
  currentTableRow2.value = row
}

// 表三模块
const tableData3 = ref([])
const isLoading3 = ref(true)
// 分页器
const currentPage3 = ref(1)
const pageSize3 = ref(40)
const total3 = ref(0)
const handleSizeChange3 = (val: number) => {
  pageSize3.value = val
  getTableList3()
}
const handleCurrentChange3 = (val: number) => {
  currentPage3.value = val
  getTableList3()
}
// 获取表数据
const getTableList3 = debounce(async () => {
  isLoading3.value = true
  let tableDataList = await LoginWork.post<any, any>('/mtlCosts/outListSizeQuery', currentTableRow.value)
  isLoading3.value = false
  tableData3.value = tableDataList.data
  // currentRow3()
}, 500)
const tableHeader3 = ref([
  {
    label: '号码',
    prop: 'sizeNo'
  },
  {
    label: '双数',
    prop: 'qty'
  }
])

const formList10 = ref([
  {
    type: 'input',
    inputPlaceholder: '外发单号',
    inputValue: ''
  },
  {
    type: 'date',
    dateLabel: '外发日期',
    dateValue: ''
  },
  {
    type: 'selectJ',
    selectValue: '',
    selectP: '厂商',
    selectLabel: '',
    selectOptions: []
  },
  {
    dateType: 'month',
    type: 'dateMonth',
    dateLabel: '对账月份',
    dateValue: ''
  },
  {
    type: 'select',
    selectValue: '',
    selectP: '结算方式',
    selectLabel: '',
    selectOptions: []
  },
  {
    type: 'input',
    inputPlaceholder: '指令',
    inputValue: ''
  },
  {
    type: 'input',
    inputPlaceholder: '型体',
    inputValue: ''
  },
  {
    type: 'input',
    inputPlaceholder: '工艺',
    inputValue: ''
  },
  {
    type: 'input',
    inputPlaceholder: '部位',
    inputValue: ''
  },
  {
    type: 'checkbox',
    checkboxLabel: '未检核',
    checked: true
  },
  {
    type: 'checkbox',
    checkboxLabel: '已检核',
    checked: true
  },
  {
    type: 'button',
    checkboxLabel: '置空',
    bgColor: '#1890FF'
  },
  {
    type: 'button',
    checkboxLabel: '导出'
  }
]) as any
const drawer = ref(false)
const findClicked10 = async (content: string) => {
  if (content === '置空') {
    formList10.value.forEach((item: any) => {
      item.inputValue = ''
      item.selectValue = ''
      item.dateValue = ''
    })
  }
  if (content === '导出') {
    const res = (await fileRequest.post(`/mtlCosts/outListDetail/export`, {
      accountName: formList10.value.find(
        (item: any) => item.selectP && Jzhcn.Find[item.selectP.split('.')[1] as keyof typeof Jzhcn.Find] === '结算方式'
      )?.selectValue,
      cfmType: cfmFlag10(),
      financeYymm: formList10.value.find(
        (item: any) => item.dateLabel && Jzhcn.Find[item.dateLabel.split('.')[1] as keyof typeof Jzhcn.Find] === '对账月份'
      )?.dateValue,
      partName: formList10.value.find(
        (item: any) => item.inputPlaceholder && Jzhcn.Find[item.inputPlaceholder.split('.')[1] as keyof typeof Jzhcn.Find] === '部位'
      )?.inputValue,
      process: formList10.value.find(
        (item: any) => item.inputPlaceholder && Jzhcn.Find[item.inputPlaceholder.split('.')[1] as keyof typeof Jzhcn.Find] === '工艺'
      )?.inputValue,
      style: formList10.value.find(
        (item: any) => item.inputPlaceholder && Jzhcn.Find[item.inputPlaceholder.split('.')[1] as keyof typeof Jzhcn.Find] === '型体'
      )?.inputValue,
      lotNo: formList10.value.find(
        (item: any) => item.inputPlaceholder && Jzhcn.Find[item.inputPlaceholder.split('.')[1] as keyof typeof Jzhcn.Find] === '指令'
      )?.inputValue,
      purDateEnd: formList10.value.find(
        (item: any) => item.dateLabel && Jzhcn.Find[item.dateLabel.split('.')[1] as keyof typeof Jzhcn.Find] === '外发日期'
      )?.dateValue?.[1],
      purDateStart: formList10.value.find(
        (item: any) => item.dateLabel && Jzhcn.Find[item.dateLabel.split('.')[1] as keyof typeof Jzhcn.Find] === '外发日期'
      )?.dateValue?.[0],
      slipNo: formList10.value.find(
        (item: any) => item.inputPlaceholder && Jzhcn.Find[item.inputPlaceholder.split('.')[1] as keyof typeof Jzhcn.Find] === '外发单号'
      )?.inputValue,
      vendor: formList10.value.find((item: any) => item.selectP && Jzhcn.Find[item.selectP.split('.')[1] as keyof typeof Jzhcn.Find] === '厂商')
        ?.selectValue,
      pageNum: currentPage.value,
      pageSize: pageSize.value
    })) as any
    const link = document.createElement('a') // 利用a标签自定义下载文件名
    let blob = new Blob([res.data]) // 创建Blob对象，设置文件类型
    link.style.display = 'none'
    //设置连接
    link.href = window.URL.createObjectURL(blob)
    const FileName = decodeURI(res.headers['content-disposition'].split(`utf-8''`)[1])
    link.download = FileName //自定义文件名字
    document.body.appendChild(link)
    //模拟点击事件
    link.click()
    document.body.removeChild(link)
  }
}
watch(
  () =>
    formList10.value.map((item: any) => {
      item.selectValue, item.inputValue, item.dateValue, item.checked
    }),
  () => {
    getTableList10()
  }
)
const tableHeader10 = ref([
  {
    backgroundColor: true,
    width: '120px',
    label: '外发单号',
    prop: 'slipNo'
  },
  {
    label: '外发日期',
    prop: 'purDate'
  },
  {
    label: '结算方式',
    prop: 'accountName'
  },
  {
    label: '对账月份',
    prop: 'financeYymm'
  },
  {
    label: '厂商',
    prop: 'vendor'
  },
  {
    label: '指令',
    prop: 'lotNo'
  },
  {
    label: '型体',
    prop: 'style'
  },
  {
    label: '底模号',
    prop: 'moldNo'
  },
  {
    label: '工艺',
    prop: 'process'
  },
  {
    label: '部位名称',
    prop: 'partName'
  },
  {
    label: '片数',
    prop: 'cutNum',
    width: '55px'
  },
  {
    label: '外发数量',
    prop: 'purQty',
    width: '55px'
  },
  {
    label: '交期',
    prop: 'deliveryDate'
  },
  {
    label: '备注',
    prop: 'purMemo'
  },
  {
    label: '单价',
    prop: 'price'
  },
  {
    label: '金额',
    prop: 'amt'
  },
  {
    label: '结算单号',
    prop: 'balanceNo'
  }
])
const tableData10 = ref([])
const cfmFlag10 = () => {
  const Unaudited = formList10.value.find((item: any) => item.type === 'checkbox' && i18n.global.t(item.checkboxLabel) === '未检核')
  const Audited = formList10.value.find((item: any) => item.type === 'checkbox' && i18n.global.t(item.checkboxLabel) === '已检核')
  if (!Unaudited || !Audited) return
  if (Unaudited.checked && Audited.checked) {
    return ''
  } else if (Unaudited.checked) {
    return 0
  } else if (Audited.checked) {
    return 1
  } else {
    ElMessage('必须至少选择一项')
    Unaudited.checked = true
    Audited.checked = true
    return ''
  }
}
const total10 = ref(0)
const currentPage10 = ref(1)
const pageSize10 = ref(40)
const handleSizeChange10 = (val: number) => {
  pageSize10.value = val
  getTableList10()
}
const handleCurrentChange10 = (val: number) => {
  currentPage10.value = val
  getTableList10()
}
const summaryData10 = ref<summaryDataType[]>([
  {
    index: 11,
    num: 0
  },
  {
    index: 15,
    num: 0
  }
])
const isLoading10 = ref(false)
const getTableList10 = async () => {
  isLoading10.value = true
  const res = (await LoginWork.post('/mtlCosts/outListDetailQuery', {
    accountName: formList10.value.find(
      (item: any) => item.selectP && Jzhcn.Find[item.selectP.split('.')[1] as keyof typeof Jzhcn.Find] === '结算方式'
    )?.selectValue,
    cfmType: cfmFlag10(),
    financeYymm: formList10.value.find(
      (item: any) => item.dateLabel && Jzhcn.Find[item.dateLabel.split('.')[1] as keyof typeof Jzhcn.Find] === '对账月份'
    )?.dateValue,
    partName: formList10.value.find(
      (item: any) => item.inputPlaceholder && Jzhcn.Find[item.inputPlaceholder.split('.')[1] as keyof typeof Jzhcn.Find] === '部位'
    )?.inputValue,
    process: formList10.value.find(
      (item: any) => item.inputPlaceholder && Jzhcn.Find[item.inputPlaceholder.split('.')[1] as keyof typeof Jzhcn.Find] === '工艺'
    )?.inputValue,
    style: formList10.value.find(
      (item: any) => item.inputPlaceholder && Jzhcn.Find[item.inputPlaceholder.split('.')[1] as keyof typeof Jzhcn.Find] === '型体'
    )?.inputValue,
    lotNo: formList10.value.find(
      (item: any) => item.inputPlaceholder && Jzhcn.Find[item.inputPlaceholder.split('.')[1] as keyof typeof Jzhcn.Find] === '指令'
    )?.inputValue,
    purDateEnd: formList10.value.find(
      (item: any) => item.dateLabel && Jzhcn.Find[item.dateLabel.split('.')[1] as keyof typeof Jzhcn.Find] === '外发日期'
    )?.dateValue?.[1],
    purDateStart: formList10.value.find(
      (item: any) => item.dateLabel && Jzhcn.Find[item.dateLabel.split('.')[1] as keyof typeof Jzhcn.Find] === '外发日期'
    )?.dateValue?.[0],
    slipNo: formList10.value.find(
      (item: any) => item.inputPlaceholder && Jzhcn.Find[item.inputPlaceholder.split('.')[1] as keyof typeof Jzhcn.Find] === '外发单号'
    )?.inputValue,
    vendor: formList10.value.find((item: any) => item.selectP && Jzhcn.Find[item.selectP.split('.')[1] as keyof typeof Jzhcn.Find] === '厂商')
      ?.selectValue,
    pageNum: currentPage.value,
    pageSize: pageSize.value
  })) as any
  if (res.code === 200) {
    isLoading10.value = false
    tableData10.value = res.data.dtos.map((item: any) => {
      if (item.cfmFlag === 'Y') item.backgroundColor = '#80FF00'
      return item
    })
    total10.value = res.data.total
    summaryData10.value[0].num = res.data.sum.orderQtySum
    summaryData10.value[1].num = res.data.sum.amtSum
  } else {
    JMessage.error(res.message)
  }
}
const currentTable10Row = ref({}) as any
const currentRow10 = async (row: any = tableData10.value[0]) => {
  currentTable10Row.value = row
  getTableList11()
}

const formList11 = ref([
  {
    dateType: 'month',
    type: 'dateMonth',
    dateLabel: '对账月份',
    dateValue: ''
  },
  {
    type: 'selectJ',
    selectValue: '',
    selectP: '厂商',
    selectLabel: '',
    selectOptions: []
  },
  {
    type: 'button',
    checkboxLabel: '导出结算清单'
  }
]) as any
const findClicked11 = async (content: string) => {
  if (content === '导出结算清单') {
    if (formList11.value[0].dateValue === '' && formList11.value[1].selectValue === '') {
      JMessage.error('请选择对账月份和厂商')
      return
    }
    const res = (await fileRequest.post(`/mtlCosts/outListFinish/export`, {
      pageSize: -1,
      financeYymm: formList11.value[0].dateValue,
      vendor: formList11.value[1].selectValue
    })) as any
    const link = document.createElement('a') // 利用a标签自定义下载文件名
    let blob = new Blob([res.data]) // 创建Blob对象，设置文件类型
    link.style.display = 'none'
    //设置连接
    link.href = window.URL.createObjectURL(blob)
    const FileName = decodeURI(res.headers['content-disposition'].split(`utf-8''`)[1])
    link.download = FileName //自定义文件名字
    document.body.appendChild(link)
    //模拟点击事件
    link.click()
    document.body.removeChild(link)
  }
}
const getTableList11 = async () => {
  const res = (await LoginWork.post('/mtlCosts/outListSizeQuery', currentTable10Row.value)) as any
  if (res.code === 200) {
    tableData11.value = res.data
  } else {
    JMessage.error(res.message)
  }
}
const tableData11 = ref([])
const tableHeader11 = ref([
  {
    label: '号码',
    prop: 'sizeNo',
    width: '55px'
  },
  {
    label: '双数',
    prop: 'qty'
  }
])

const getSelectList = async () => {
  let res = await service.put<any, any>('/back/getVendorSearch', {
    pageNum: -1,
    pageSize: -1
  })
  res.list.map((Vendor: any) => {
    formList.value[2].selectOptions?.push({
      label: Vendor.vendorName,
      key: `${Vendor.vendorNo}`,
      value: `${Vendor.vendorName}`
    })
  })
  formList2.value
    .find((item: any) => item.selectP && Jzhcn.Find[item.selectP.split('.')[1] as keyof typeof Jzhcn.Find] === '结算方式')
    ?.selectOptions?.push(
      {
        optionKey: `荣阳大货`,
        optionLabel: `荣阳大货`,
        optionValue: `荣阳大货`
      },
      {
        optionKey: `荣信`,
        optionLabel: `荣信`,
        optionValue: `荣信`
      },
      {
        optionKey: `KINGLIKE`,
        optionLabel: `KINGLIKE`,
        optionValue: `KINGLIKE`
      }
    )
  formList10.value
    .find((item: any) => item.selectP && Jzhcn.Find[item.selectP.split('.')[1] as keyof typeof Jzhcn.Find] === '结算方式')
    ?.selectOptions?.push(
      {
        optionKey: `荣阳大货`,
        optionLabel: `荣阳大货`,
        optionValue: `荣阳大货`
      },
      {
        optionKey: `荣信`,
        optionLabel: `荣信`,
        optionValue: `荣信`
      },
      {
        optionKey: `KINGLIKE`,
        optionLabel: `KINGLIKE`,
        optionValue: `KINGLIKE`
      }
    )
}
const getSelectList2 = async () => {
  let res = await service.put<any, any>('/back/getVendorSearch', {
    pageNum: -1,
    pageSize: -1
  })
  // let res = await service.get<any, any>('/back/getVendorCompanyName')
  res.list.map((Vendor: any) => {
    formList10.value[2].selectOptions?.push({
      label: Vendor.vendorName,
      key: `${Vendor.vendorNo}`,
      value: `${Vendor.vendorName}`
    })
    formList11.value[1].selectOptions?.push({
      label: Vendor.vendorName,
      key: `${Vendor.vendorNo}`,
      value: `${Vendor.vendorName}`
    })
  })
}
watch(drawer, (val: any) => {
  if (val === false) {
    formList10.value[2].selectOptions = []
    formList11.value[1].selectOptions = []
  }
})
onMounted(() => {
  getSelectList()
})
</script>

<style lang="less" scoped></style>
